<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/menu.css" media="all" />
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/request.css" media="all" />
<script type="text/javascript"  src="<{$ipath}>public/js/head.js"></script>
<script type="text/javascript" src="<{$ipath}>wx/js/jquery.min.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/ajaxfileupload.js"></script>
<script>
function setdata(mode,type,value){
	var title = $("#save_menu_title");
	var con = $("#save_menu_con");
}
function addmenu(){
	var mnum = $(".menufoot .create").length;
	var maxtnum = parseInt($("#maxtnum").val());
	var str='<li class="create menu'+maxtnum+' tmenu" data-tnum="'+maxtnum+'" style="float:left"><a onClick="selectmenu(this)">菜单名称</a><div class="smenu"><ul class="smenu_item"><li class="addsmenu" onclick="addsmenu(this)"><i class="addicon"></i></li></ul><i class="arrow arrow_out"></i><i class="arrow arrow_in"></i></div></li>';
	var w=0;
	if(mnum==1){
		w=50;
	}else{
		w=33;
	}
	$(".addmenu").remove();
	if(mnum==1 || mnum==2){
		str+='<li class="create addmenu" style="float:left;"><a onClick="addmenu()"><i class="addicon"></i></a></li>';
		$(".menufoot").append(str);
	}else if(mnum==3){
		$(".menufoot").append(str);
	}
	$(".create").width(w+"%");
	$("#maxtnum").val(maxtnum+1);
	$(".wxmenu h1").append('<input type="hidden" id="maxsnum'+maxtnum+'" value="0">');
}
function addsmenu(obj){
	var sitem = $(obj).parent();
	var up=$(obj).parent().parent().parent().attr("data-tnum");
	var maxsnum = parseInt($("#maxsnum"+up).val());
	var snum = sitem.children("li").length;
	sitem.prepend('<li data-num="'+maxsnum+'" class="list'+maxsnum+'"><a onclick="editsmenu(this)">子菜单名称</a></li>');
	$("#maxsnum"+up).val(maxsnum+1);
	if(snum>=5){
		sitem.find(".addsmenu").remove();
	}
}
function selectmenu(obj){
	$(".menufoot").find("a").removeClass("menuselect");
	$(obj).addClass("menuselect");
	$(".smenu").hide();
	$(obj).next(".smenu").show();
	$(".tips_global").hide();
	$(".editor").show();
	$("#selmode").attr("data-type","title");
	var tnum = $(obj).parent("li").attr("data-tnum");
	$("#selmode").val(tnum);
	if($('#save_menu_title input[name="title'+tnum+'"]').length>0 && $('#save_menu_title input[name="title'+tnum+'"]').val() != ''){
		$(".editor_inner>h2").children("span").html($('#save_menu_title input[name="title'+tnum+'"]').val());
		$(".frm_input").val($('#save_menu_title input[name="title'+tnum+'"]').val())
		$(obj).html($('#save_menu_title input[name="title'+tnum+'"]').val());
	}else{
		$(".editor_inner>h2").children("span").html('菜单名称');
		$(".frm_input").val('菜单名称')
	}
	if($(obj).next("div").children("ul").children("li").length>1){
		$(".tips_normal").show();
		$(".frm_menu_con").hide();
	}else{
		$(".tips_normal").hide();
		$(".frm_menu_con").show();
		if($('#save_menu_con input[name="type'+tnum+'"]').val() == 'view'){
			showconmode(2);
		}else if($('#save_menu_con input[name="type'+tnum+'"]').val() == 'click'){
			showconmode(3);
		}else{
			showconmode(1);
		}
	}
}
function editsmenu(obj){
	$(".tips_global").hide();
	$(".editor").show();
	$(".menufoot").find("a").removeClass("menuselect");
	$(obj).addClass("menuselect");
	$("#selmode").attr("data-type","stitle");
	var tnum = $(obj).parent().parent().parent().parent().attr("data-tnum");
	$("#selmode").attr("data-up",tnum);
	$("#selmode").val($(obj).parent("li").attr("data-num"));
	var snum = $(obj).parent().attr("data-num");
	if($('#save_menu_title input[name="stitle'+tnum+'['+snum+']"]').length>0){
		$(".editor_inner>h2").children("span").html($('#save_menu_title input[name="stitle'+tnum+'['+snum+']"]').val());
		$(".frm_input").val($('#save_menu_title input[name="stitle'+tnum+'['+snum+']"]').val())
		$(obj).html($('#save_menu_title input[name="stitle'+tnum+'['+snum+']"]').val());
	}else{
		$(".editor_inner>h2").children("span").html('子菜单名称');
		$(".frm_input").val('子菜单名称')
	}
	$(".editor_inner>h2").children("span").html();
	$(".tips_normal").hide();
	$(".frm_menu_con").show();
	if($('#save_menu_con input[name="stype'+tnum+'['+snum+']"]').val() == 'view'){
		showconmode(2);
	}else if($('#save_menu_con input[name="stype'+tnum+'['+snum+']"]').val() == 'click'){
		showconmode(3);
	}else{
		showconmode(1);
	}
}

function showwxput(n){
	for(var i=1;i<6;i++){
		$("#putcon"+i).hide();
		$(".ptit i").removeClass("select");
	}
	var temarr=new Array();
	temarr[1]="txt";
	temarr[2]="img";
	temarr[3]="voice";
	temarr[4]="video";
	temarr[5]="news";
	$("#putcon"+n).show();
	if($("#putcon"+n+" .request_item").find("input").length>0){
		$("#putcon"+n+" .request_item").show();
		$("#putcon"+n+" .request_add").hide();
		$("#putcon"+n).children("h5").find(".setbutton").show();
		$("#putcon"+n).children("h5").find(".addbutton").hide();
		if($("#putcon"+n).children("h5").find(".delbutton").length<1){
			$("#putcon"+n).children("h5").append('<input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材" />');
		}
	}
	$("#type").val(n);
	$("."+temarr[n]+"icon i").addClass("select");
}
function checkfrm(){
	var type = $("#type").val();
	if(type==1){
		if($("#content").val()=='' || $("#content").val()==null){
			alert('请填写自动回复内容');
			return false;
		}else{
			return true;
		}
	}else if(type==3){
		if($("#title").val()=='' || $("#title").val()==null){
			alert('请填写语音标题');
			return false;
		}else{
			return true;
		}
	}else if(type==4){
		if($("#tit").val()=='' || $("#tit").val()==null){
			alert('请填写视频标题');
			return false;
		}else if($("#desc").val()=='' || $("#desc").val()==null){
			alert('请填写视频描述');
			return false;
		}else{
			return true;
		}
	}
}
function delwxrequest(id,type){
	var url='?g=wx&m=weixin&a=delmedia&id='+id;
	$.get(url,function(data){
		if(data=='' || data==null){
			alert('删除失败，请重试');
			return false;
		}
		if(data.error==1000 || data.error=='1000'){
			$("#putcon"+type).children("div").eq(0).hide();
			$("#putcon"+type).children("div").eq(1).show();
		}
	},'json');
}
function delmedia(obj){
	$(obj).parent().parent().children(".request_item").html('');
	$(obj).parent().parent().children(".request_item").hide();
	$(obj).parent().children(".setbutton").hide();
	if($(obj).parent().find(".addbutton").length>0){
		$(obj).parent().find(".addbutton").show();
	}
	$(obj).parent().parent().children(".request_add").show();
	$(obj).remove();
}
function showwxrequest(type){
	$("#putcon"+type).children("div").eq(0).show();
	$("#putcon"+type).children("div").eq(1).hide();
}
function showconmode(n){
	var mode = $("#selmode").attr("data-type");
	var value = parseInt($("#selmode").val());
	var title = $(".frm_menu_name .frm_input").val();
	$(".selconmode").removeAttr("checked");
	$(".selconmode").eq(n-1).attr("checked","checked");
	if(n==1){
		$(".frm_menu_con").find(".lable input").removeAttr("checked");
		$(".frm_menu_con").find(".lable input").eq(0).attr("checked","checked");
		if(mode=='title'){
			if($('#save_menu_con input[name="con'+value+'"]').length>0){
				if($('#save_menu_con input[name="type'+value+'"]').val()=='click'){
					showwxput(1);
					$("#content").val($('#save_menu_con input[name="con'+value+'"]').val());
				}else{
					if($('#save_menu_con input[name="con'+value+'"]').length>0 && $('#save_menu_con input[name="con'+value+'"]').val()!=''){
						var url = '?g=wx&m=weixin&a=getmediabyid&media_id='+$('#save_menu_con input[name="con'+value+'"]').val();
						$.get(url,function(data){
							if(data.error==1000 || data.error=='1000'){
								if(data.data.type=='img'){
									$("#putcon2 .request_item").html('<img src="'+data.data.url+'" style="max-width:300px"><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									$("#putcon2 h5").find(".delbutton").show();
									showwxput(2);
								}else if(data.data.type=='voice'){
									$("#putcon3 .request_item").html('<audio controls src="'+data.data.url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									$("#putcon3 h5").find(".delbutton").show();
									showwxput(3);
								}else if(data.data.type=='video'){
									$("#putcon4 .request_item").html('<video controls src="'+data.data.url+'" width="300">您的浏览器不支持H5视频播放</video><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									$("#putcon4 h5").find(".delbutton").show();
									showwxput(4);
								}else if(data.data.type=='news'){
									$("#putcon5 .request_item").html('<dl><img src="'+data.data.url+'" width="100%" /><dd>'+data.data.content.title+'</dd></dl><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									$("#putcon5 h5").find(".delbutton").show();
									showwxput(5);
								}
							}
						},'json');
					}else{
						$("#putcon2 .request_item").html('');
						showwxput(2);
					}
				}
			}
		}else if(mode=='stitle'){
			var up = parseInt($("#selmode").attr("data-up"));
			if($('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
				if($('#save_menu_con input[name="stype'+up+'['+value+']"]').val()=='click'){
					$("#content").val($('#save_menu_con input[name="scon'+up+'['+value+']"]').val());
					showwxput(1);
				}else{
					if($('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
						 var url = '?g=wx&m=weixin&a=getmediabyid&media_id='+$('#save_menu_con input[name="scon'+up+'['+value+']"]').val();
						$.get(url,function(data){
							if(data.error==1000 || data.error=='1000'){
								if(data.data.type=='img'){
									$("#putcon2 .request_item").html('<img src="'+data.data.url+'" style="max-width:300px"><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									showwxput(2);
								}else if(data.data.type=='voice'){
									$("#putcon3 .request_item").html('<audio controls src="'+data.data.url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									showwxput(3);
								}else if(data.data.type=='video'){
									$("#putcon4 .request_item").html('<video controls src="'+data.data.url+'" width="300">您的浏览器不支持H5视频播放</video><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									showwxput(4);
								}else if(data.data.type=='news'){
									$("#putcon5 .request_item").html('<dl><img src="'+data.data.url+'" width="100%" /><dd>'+data.data.content.title+'</dd></dl><input type="hidden" name="media_id" value="'+data.data.media_id+'">');
									showwxput(5);
								}
							}else{
								alert(error.msg);
							}
						},'json');
					}else{
						$("#putcon2 .request_item").html('');
						showwxput(2);
					}
				}
			}
		}
		$("#menu_con_url").hide();
		$("#menu_con_key").hide();
		$("#menu_con_event").show();
	}else if(n==2){
		$(".frm_menu_con").find(".lable input").removeAttr("checked");
		$(".frm_menu_con").find(".lable input").eq(1).attr("checked","checked");
		if(mode=='title'){
			if($('#save_menu_con input[name="type'+value+'"]').val()=='view' && $('#save_menu_con input[name="con'+value+'"]').length>0){
				$(".url_input").val($('#save_menu_con input[name="con'+value+'"]').val());
			}
		}else if(mode=='stitle'){
			var up = parseInt($("#selmode").attr("data-up"));
			if($('#save_menu_con input[name="stype'+up+'['+value+']"]').val()=='view' && $('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
				$(".url_input").val($('#save_menu_con input[name="scon'+up+'['+value+']"]').val());
			}
		}
		$("#menu_con_url").show();
		$("#menu_con_key").hide();
		$("#menu_con_event").hide();
	}else if(n==3){
		$(".frm_menu_con").find(".lable input").removeAttr("checked");
		$(".frm_menu_con").find(".lable input").eq(2).attr("checked","checked");
		if(mode=='title'){
			if($('#save_menu_con input[name="type'+value+'"]').val()=='click' && $('#save_menu_con input[name="con'+value+'"]').length>0){
				$(".key_input").val($('#save_menu_con input[name="con'+value+'"]').val());
			}
		}else if(mode=='stitle'){
			var up = parseInt($("#selmode").attr("data-up"));
			if($('#save_menu_con input[name="stype'+up+'['+value+']"]').val()=='click' && $('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
				$(".key_input").val($('#save_menu_con input[name="scon'+up+'['+value+']"]').val());
			}
		}
		$("#menu_con_url").hide();
		$("#menu_con_key").show();
		$("#menu_con_event").hide();
	}else{
		return false;
	}
}
function save_smart(n,fname){
	var url='?g=wx&m=weixin&a=savesmart';
	var data={};
	var dl=$("#datalist").children("span");
	if($("#showlist li").length >= 5){
		alert('一个规则最多可以增加5条回复');
		return false;
	}
	data.type = n;
	if(n==1){
		data.content = $("#content").val();
	}else if(n==3){
		data.title = $("#vtit").val();
	}else if(n==4){
		data.title = $("#tit").val();
		data.desc = $("#desc").val();
	}
	if(n>1){
		$.ajaxFileUpload({
			url:url,
			dataType:'json',
			fileElementId:fname,
			type:'post',
			secureuri:false,
			data:data,
			success:function(data){
				if(data.error==1000 || data.error=='1000'){
					if(data.type==2 || data.type=='2'){
						$("#putcon2 .request_item").html('<li><img src="'+data.msg+'" style="max-width:300px" /><input type="hidden" name="media_id" value="'+data.media_id+'" /></li>');
						$("#putcon2 h5").append('<input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材">');
						$("#putcon2 .request_add").hide();
						$("#putcon2 .request_item").show();
						$("#putcon2 .setbutton").show();
						$("#putcon2 .addbutton").hide()
					}
					if(data.type==3 || data.type=='3'){
						$("#putcon3 .request_item").html('<li><audio controls src="'+data.msg+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id" value="'+data.media_id+'" /></li>');
						$("#putcon3 h5").append('<input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材">');
						$("#putcon3 .request_item").show();
						$("#putcon3 .request_add").hide();
						$("#putcon3 .setbutton").show();
						$("#putcon3 .addbutton").hide()
					}
					if(data.type==4 || data.type=='4'){
						$("#putcon4 .request_item").html('<li><video width="300" controls src="'+data.msg+'">您的浏览器不支持H5视频播放</video><input type="hidden" name="media_id" value="'+data.media_id+'" /></li>');
						$("#putcon4 h5").append('<input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材">');
						$("#putcon4 .request_item").show();
						$("#putcon4 .request_add").hide();
						$("#putcon4 .setbutton").show();
						$("#putcon4 .addbutton").hide()
					}
				}else{
					alert(data.msg);
					return false;
				}
			},
		});
	}else{
		return false;
	}
}
$(function(){
	$(".frm_menu_name .frm_input").blur(function(){
		var mode = $("#selmode").attr("data-type");
		var value = parseInt($("#selmode").val());
		var title = $(".frm_menu_name .frm_input").val();
		if(mode=='title'){
			$(".menufoot .menu"+value).children("a").html(title);
			if($('#save_menu_title input[name="title'+value+'"]').length>0){
				$('#save_menu_title input[name="title'+value+'"]').val(title);
			}else{
				$("#save_menu_title").append('<input type="hidden" name="title'+value+'" value="'+title+'">');
			}
			return false;
		}else if(mode=='stitle'){
			var up = parseInt($("#selmode").attr("data-up"));
			$(".menufoot .menu"+up).children("div").children("ul").children(".list"+value).children("a").html(title);
			if($('#save_menu_title input[name="stitle'+up+'['+value+']"]').length>0){
				$('#save_menu_title input[name="stitle'+up+'['+value+']"]').val(title);
			}else{
				$("#save_menu_title").append('<input type="hidden" name="stitle'+up+'['+value+']" value="'+title+'">');
			}
			return false;
		}else{
			return false;
		}
	});
	$(".url_input").blur(function(){
		var mode = $("#selmode").attr("data-type");
	var value = parseInt($("#selmode").val());
	var url = $(".url_input").val();
	if(mode=='title'){
		if($('#save_menu_con input[name="type'+value+'"]').length>0){
			$('#save_menu_con input[name="type'+value+'"]').val("view");
		}else{
			$("#save_menu_con").append('<input type="hidden" name="type'+value+'" value="view" />');
		}
		if($('#save_menu_con input[name="con'+value+'"]').length>0){
			$('#save_menu_con input[name="con'+value+'"]').val(url);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="con'+value+'" value="'+url+'" />');
		}
	}else if(mode=='stitle'){
		var up = parseInt($("#selmode").attr("data-up"));
		if($('#save_menu_con input[name="stype'+up+'['+value+']"]').length>0){
			$('#save_menu_con input[name="stype'+up+'['+value+']"]').val("view");
		}else{
			$("#save_menu_con").append('<input type="hidden" name="stype'+up+'['+value+']" value="view">');
		}
		if($('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
			$('#save_menu_con input[name="scon'+up+'['+value+']"]').val(url);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="scon'+up+'['+value+']" value="'+url+'">');
		}
	}else{
		return false;
	}
	});
	$(".key_input").blur(function(){
		setkeyvalue();
	})
	$(".setbutton").click(function(){
		$(this).parent().children(".request_item").find("input").val();
	});
});
function serkvreturn(){
		setkeyvalue();
		alert('关键词设置成功');
	}
function setkeyvalue(){
	var mode = $("#selmode").attr("data-type");
	var value = parseInt($("#selmode").val());
	var key = $(".key_input").val();
	if(mode=='title'){
		if($('#save_menu_con input[name="type'+value+'"]').length>0){
			$('#save_menu_con input[name="type'+value+'"]').val("click");
		}else{
			$("#save_menu_con").append('<input type="hidden" name="type'+value+'" value="click" />');
		}
		if($('#save_menu_con input[name="con'+value+'"]').length>0){
			$('#save_menu_con input[name="con'+value+'"]').val(key);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="con'+value+'" value="'+key+'" />');
		}
	}else if(mode=='stitle'){
		var up = parseInt($("#selmode").attr("data-up"));
		if($('#save_menu_con input[name="stype'+up+'['+value+']"]').length>0){
			$('#save_menu_con input[name="stype'+up+'['+value+']"]').val("click");
		}else{
			$("#save_menu_con").append('<input type="hidden" name="stype'+up+'['+value+']" value="click">');
		}
		if($('#save_menu_con input[name="scon'+up+'['+value+']"]').length>0){
			$('#save_menu_con input[name="scon'+up+'['+value+']"]').val(key);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="scon'+up+'['+value+']" value="'+key+'">');
		}
	}else{
		return false;
	}
}
function delmenu(){
	var mode = $("#selmode").attr("data-type");
	var value = parseInt($("#selmode").val());
	var title = $(".frm_menu_name .frm_input").val();
	if(mode=='title'){
		var titname = $(".menufoot .menu"+value).children("a").html();
		if(confirm('删除后 "'+titname+'" 菜单下设置的内容将被删除，确认删除吗?')){
			$(".menufoot .menu"+value).remove();
			var mnum = $(".menufoot .tmenu").length;
			var w=0;
			var str;
			if(mnum<1){
				$('.menufoot').html('<li class="create addmenu"><a onclick="addmenu()"><i class="addicon"></i> 添加菜单</a></li>');
			}else{
				if(mnum==1){
					w=50;
				}else{
					w=33;
					$(".menufoot").append('<li style="float: left;" class="create addmenu"><a onclick="addmenu()"><i class="addicon"></i></a></li>');
				}
				$(".create").width(w+"%");
			}
			$('#save_menu_title input[name="title'+value+'"]').remove();
			$('#save_menu_con input[name="type'+value+'"]').remove();
			$('#save_menu_con input[name="con'+value+'"]').remove();
			$('#save_menu_title input[name^="stitle'+value+'"]').remove();
			$('#save_menu_con input[name^="scon'+value+'"]').remove();
			$('#save_menu_con input[name^="stype'+value+'"]').remove();
			$(".editor").hide();
			$(".tips_global").show();
		}
		return false;
	}else if(mode=='stitle'){
		var up = parseInt($("#selmode").attr("data-up"));
		var stitname = $(".menufoot .menu"+up).children("div").children("ul").children(".list"+value).children("a").html();
		if(confirm('删除后 "'+stitname+'" 菜单下设置的内容将被删除，确认删除吗?')){
			$(".menufoot .menu"+up).children("div").children("ul").children(".list"+value).remove();
			$('#save_menu_title input[name="stitle'+up+'['+value+']"]').remove();
			$('#save_menu_con input[name="stype'+up+'['+value+']"]').remove();
			$('#save_menu_con input[name="scon'+up+'['+value+']"]').remove();
			if($(".menufoot .menu"+up).children("div").children("ul").children("li").length<5 && $(".menufoot .menu"+up).children("div").children("ul").children(".addsmenu").length<1){
				$(".menufoot .menu"+up).children("div").children("ul").append('<li class="addsmenu" onclick="addsmenu(this)"><i class="addicon"></i></li>');
			}
		}
		return false;
	}else if(mode=='con'){
		
	}else if(mode=='scon'){
		
	}else{
		return false;
	}
}
function setmenu(n){
	var mode = $("#selmode").attr("data-type");
	var value = parseInt($("#selmode").val());
	var con;
	var type;
	if(n==1){
		con=$("#content").val();
		$("#content").val('');
		type='click';
	}else{
		con=$("#putcon"+n).children(".request_item").find("input").val();
		type='media_id';
	}
	if(con=='' || con==null){
		alert('不能设定空的内容');
		return false;
	}
	if(n>1){
		$("#putcon"+n).children(".request_item").html('');
		$("#putcon"+n).find(".setbutton").hide();
		$("#putcon"+n).find(".delbutton").remove();
		$("#putcon"+n).find(".addbutton").show();
		$("#putcon"+n).children(".request_add").show();
	}
	if(mode=='title'){
		if($('#save_menu_con input[name="type'+value+'"]').length>0){
			$('#save_menu_con input[name="type'+value+'"]').val(type);
			$('#save_menu_con input[name="con'+value+'"]').val(con);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="type'+value+'" value="'+type+'" /><input type="hidden" name="con'+value+'" value="'+con+'" />');
		}
	}else if(mode=='stitle'){
		up=$("#selmode").attr("data-up");
		if($('#save_menu_con input[name="stype'+up+'['+value+']"]').length>0){
			$('#save_menu_con input[name="stype'+up+'['+value+']"]').val(type);
			$('#save_menu_con input[name="scon'+up+'['+value+']"]').val(con);
		}else{
			$("#save_menu_con").append('<input type="hidden" name="stype'+up+'['+value+']" value="'+type+'" /><input type="hidden" name="scon'+up+'['+value+']" value="'+con+'" />');
		}
	}
	alert('菜单设置成功');
}
</script>
<style>.topnav{ width:94%;margin:0 auto;padding-top:16px;font-size:14px;line-height:18px;}.topnav *{color:#333;}</style>
</head>

<body>
<div class="topnav"><a class="level-1" href="?g=index&m=index&a=platform">我的服务</a>><a class="level-2" href="?g=index&m=index&a=wxpla">微信公众号</a>><span class="level-3">自定义菜单</span></div>
<div class="wxmenu">
	<h1>自定义菜单<input type="hidden" id="selmode" value="" /><input type="hidden" id="maxtnum" value="<{if !empty($titlenum)}><{$titlenum + 1}><{else}>1<{/if}>" />
    <input type="hidden" id="maxsnum1" value="<{if !empty($view.1.stnum)}><{$view.1.stnum}><{else}>0<{/if}>" /><input type="hidden" id="maxsnum2" value="<{if !empty($view.2.stnum)}><{$view.2.stnum}><{else}>0<{/if}>" /><input type="hidden" id="maxsnum3" value="<{if !empty($view.3.stnum)}><{$view.3.stnum}><{else}>0<{/if}>" />
    <em style="margin-top:-20px;">使用说明</em></h1>
    <div class="wxmenu_show">
    	<div id="wxmenu_window">
        	<div class="menuhead">dsfsdf</div>
            <ul class="menufoot">
            <{if !empty($view)}>
            	<{foreach item=v key=k from=$view name=foo}>
                	<{if !empty($v.title)}>
                		<li class="create menu<{$k}> tmenu" data-tnum="<{$k}>" style="float: left; width:<{if $titlenum>1}>33<{else}>50<{/if}>%">
                        	<a onclick="selectmenu(this)"><{$v.title}></a>
                            <{if !empty($v.stitle)}>
                            <div class="smenu" style="display:block">
                                <ul class="smenu_item">
                                <{foreach item=vv key=kk from=$v.stitle}>
                                	<{if !empty($vv)}>
                                		<li data-num="<{$kk}>" class="list<{$kk}>"><a onclick="editsmenu(this)"><{$vv}></a></li>
                                    <{/if}>
                                <{/foreach}>
                                <{if $v.stnum<5}>
                                	<li class="addsmenu" onclick="addsmenu(this)"><i class="addicon"></i></li>
                                <{/if}>
                                </ul><i class="arrow arrow_out"></i><i class="arrow arrow_in"></i>
                            </div>
                            <{else}>
                             <div class="smenu"><ul class="smenu_item"><li class="addsmenu" onclick="addsmenu(this)"><i class="addicon"></i></li></ul><i class="arrow arrow_out"></i><i class="arrow arrow_in"></i></div>
                            <{/if}>
                        </li>
                    <{/if}>
                <{/foreach}>
                <{if $titlenum==2}>
                <li class="create addmenu" style="float: left; width: 33%;"><a onclick="addmenu()"><i class="addicon"></i></a></li>
                <{elseif $titlenum==1}>
                <li class="create addmenu" style="float: left; width: 50%;"><a onclick="addmenu()"><i class="addicon"></i></a></li>
                <{/if}>
            <{else}>
            	<li class="create addmenu">
                	<a onClick="addmenu()"><i class="addicon"></i> 添加菜单</a>
                </li>
            <{/if}>
            </ul>
        </div>
        <div id="wxmenu_config">
        	<div class="tips_global" style="display:block"><{if !empty($view)}>您已添加过菜单<br>如需修改请点击左侧模拟菜单编辑<{else}>点击左侧加号添加菜单<br>点击菜单名称设置菜单<{/if}></div>
            <div class="editor">
            	<div class="editor_inner">
                	<h2><span>菜单名称</span><em onClick="delmenu()">删除菜单</em></h2>
                    <div id="view">
                        <div class="frm_menu_name">
                        	<ul><span>菜单名称</span> <input type="text" class="frm_input" value="菜单名称" /></ul>
                            <p class="tips_fail">请输入菜单名称</p>
                            <p class="tips_fail">字数超过上限</p>
                            <p class="tips_normal">字数不超过4个汉字或8个字母</p>
                        </div>
                        <div class="tips_normal" style="display:none">已添加子菜单，仅可设置菜单名称</div>
                        <div class="frm_menu_con">
                        	<ul>菜单内容 <label class="lable"><input type="radio" name="selconmode" onClick="showconmode(1)" checked />发送消息</label> <label  class="lable"><input  name="selconmode" type="radio" onClick="showconmode(2)" />跳转网页</label> <label  class="lable"><input  name="selconmode" type="radio" onClick="showconmode(3)" />关键词</label></ul>
                            <ul id="menu_con_url">
                            	<li class="tips_normal">订阅者点击该子菜单会跳到以下链接</li>
                                <li>页面地址 <input type="text" class="url_input" id="urladdress" /><a onclick="top.showdiv('above')" class="a_choose">从功能库添加</a></li>
                            </ul>
                            <ul id="menu_con_key">
                            	<li class="tips_normal">订阅者点击该菜单会调用相应的关键词回复</li>
                                <li>关键词 <input type="text" class="key_input" /> <input type="button" class="wxsubmit"  onClick="serkvreturn()" value="设定为菜单内容"></li>
                            </ul>
                            <ul id="menu_con_event" style="display:block">
                            	<div class="wxinput">
                                <ul class="ptit">
                                <!--<li class="txticon"><a onClick="showwxput(1)"><i class="icon select"></i><span>文字</span></a></li>-->
                                <li  class="newsicon"><a onClick="showwxput(5)"><i class="icon select"></i>图文</a></li>
                                <li class="imgicon"><a onClick="showwxput(2)"><i class="icon"></i>图片</a></li>
                                <li  class="voiceicon"><a onClick="showwxput(3)"><i class="icon"></i>语音</a></li>
                                <li  class="videoicon"><a onClick="showwxput(4)"><i class="icon"></i>视频</a></li>
                                </ul>
                                <!--<ul class="pcon" id="putcon1" style="display:block"><textarea name="content" id="content"></textarea>
                                <h5><input type="button" class="wxsubmit" onClick="setmenu(1)"  value="设定为菜单内容"></h5></ul>-->
                                <ul class="pcon" id="putcon5" style="display:block">
                                <div class="request_item"></div>
                                <div class="request_add">
                                <li class="selmate">
                                        <a onClick="getmedialist(5)"><i></i>
                                        <h2 class="space_bottom">从素材库选择</h2></a>
                                    </li>
                                    <li class="selmate">
                                        <a href="?g=wx&m=weixin&a=wxnews" target="_blank"><i></i>
                                        <h2>新建图文消息</h2></a>
                                    </li>
                                </div>
                                <h5><input type="button" class="wxsubmit setbutton"  onClick="setmenu(5)" value="设定为菜单内容"></h5>
                                </ul>
                                <ul class="pcon" id="putcon2" >
                                <div class="request_item"></div>
                                <div class="request_add">
                                    <li class="selmate">
                                        <a onClick="getmedialist(2)"><i></i>
                                        <h2 class="space_bottom">从素材库选择</h2></a>
                                    </li>
                                    <li class="selmate">
                                        <i><input type="file" name="img" id="img" class="fhidden" /></i>
                                        <h2 class="space_bottom">本地图片</h2>
                                    </li>
                                </div>
                                <h5><input type="button" class="wxsubmit setbutton" onClick="setmenu(2)" value="设定为菜单内容"> <input type="button" class="wxsubmit addbutton" onclick="save_smart(2,'img')" value="上传图片"></h5>
                                </ul>
                                <ul class="pcon" id="putcon3">
                                <div class="request_item"></div>
                                <div class="request_add">
                                    <li class="selmate">
                                        <a onClick="getmedialist(3)"><i></i>
                                        <h2 class="space_bottom">从素材库选择</h2></a>
                                    </li>
                                    <li class="selmate">
                                        <i><input type="file" name="voice" id="voice" class="fhidden" /></i>
                                        <h2>本地语音</h2>
                                        <dd style="margin-bottom:30px;">语音标题：<input type="text" placeholder="请输入语音文件标题" id="title" name="title" /></dd>
                                    </li>
                                </div>
                                <h5><input type="button" class="wxsubmit setbutton"  onClick="setmenu(3)" value="设定为菜单内容"> <input type="button" class="wxsubmit addbutton" onclick="save_smart(3,'voice')" value="上传语音"></h5>
                                </ul>
                                <ul class="pcon" id="putcon4">
                                <div class="request_item"></div>
                                <div class="request_add">
                                <li class="selmate">
                                        <a onClick="getmedialist(4)"><i></i>
                                        <h2 class="space_bottom">从素材库选择</h2></a>
                                    </li>
                                    <li class="selmate">
                                        <i><input type="file" name="video" id="video" class="fhidden" /></i>
                                        <h2>本地视频</h2>
                                        <dd>视频标题：<input type="text" placeholder="请输入视频文件标题" name="tit" id="tit" /></dd>
                                        <dd style="margin-bottom:5px;">视频说明：<input type="text" placeholder="请输入视频文件简介" name="desc" id="desc" /></dd>
                                    </li>
                                </div>
                                <h5><input type="button" class="wxsubmit setbutton" onClick="setmenu(4)" value="设定为菜单内容"> <input type="button" class="wxsubmit addbutton" onclick="save_smart(4,'video')" value="上传视频"></h5>
                                </ul>
                                </div>
                            </ul>
                        </div>
                    </div>
                </div>
                <span class="editor_arrow_wrp">
                    <i class="editor_arrow editor_arrow_out"></i>
                    <i class="editor_arrow editor_arrow_in"></i>
                </span>
            </div>
        </div>
    </div>
    <div class="menu_save">
    <form action="?g=wx&m=weixin&a=menusave" method="post" target="hiddfrm">
    <span id="save_menu_title">
    	<{if !empty($view)}>
        	<{foreach item=v key=k from=$view}>
            	<input name="title<{$k}>" type="hidden" value="<{$v.title}>" />
                <{if !empty($v.stitle)}>
                	<{foreach item=vv key=kk from=$v.stitle}>
                    	<input name="stitle<{$k}>[<{$kk}>]" type="hidden" value="<{$vv}>" />
                    <{/foreach}>
                <{/if}>
            <{/foreach}>
        <{/if}>
    </span>
    <span id="save_menu_con">
    	<{if !empty($view)}>
        	<{foreach item=v key=k from=$view}>
            	<input name="type<{$k}>" type="hidden" value="<{$v.type}>" />
                <input name="con<{$k}>" type="hidden" value="<{$v.con}>" />
                <{if !empty($v.stype)}>
                	<{foreach item=vv key=kk from=$v.stype}>
                    	<input name="stype<{$k}>[<{$kk}>]" type="hidden" value="<{$vv}>" />
                    <{/foreach}>
                <{/if}>
                <{if !empty($v.scon)}>
                	<{foreach item=vv key=kk from=$v.scon}>
                    	<input name="scon<{$k}>[<{$kk}>]" type="hidden" value="<{$vv}>" />
                    <{/foreach}>
                <{/if}>
            <{/foreach}>
        <{/if}>
    </span>
    	<input class="wxbutton" id="menusavebutton" type="submit" value="保存并发布" />
    </form>
    </div>
</div>
<div id="shade"></div>
<div id="showmedialist" class="hidddiv">
	<h3>选择素材<em onClick="closeshowmedialist()"><i class="icon_close"></i></em></h3>
    <ul id="showimglist"></ul>
    <ul id="showvoicelist"></ul>
    <ul id="showvideolist"></ul>
    <ul id="shownewslist"></ul>
    <h4><input type="hidden" id="mediashowid" value="" /><input type="hidden" id="mediashowurl" value="" /><input type="hidden" id="selbytype" value="" /><input type="hidden" id="mediashowtomore" value="" /><input type="button" class="wxbutton_cancel" id="mediashowsetbutton" value="确认"> <input type="button" class="wxbutton_cancel" onClick="closeshowmedialist()" value="取消" /></h4>
</div>
<script>
function getmedialist(n){
	var url;
	var type;
	var str='';
	var temp='';
	if(n==2){
		type='img';
	}else if(n==3){
		type='voice';
	}else if(n==4){
		type='video';
	}else if(n==5){
		type='news';
	}else{
		alert('选择素材类型错误');
		return false;
	}
	$("#selbytype").val(n);
	url='?g=wx&m=weixin&a=getmedialist&type='+type;
	$.get(url,function(data){
		if(data=='' || data==null){
			str+='<li class="showmedia_nono">暂时没有素材</li>';
		}else{
			if(n==2){
				for(ritem in data){
					str+='<li class="showmedia_img" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="'+data[ritem].url+'" width="120" height="120" /></li>';
				}
			}else if(n==3){
				for(ritem in data){
					str+='<li class="showmedia_voice" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="<{$ipath}>wx/images/voice_stop.png" width="60px" onclick="playaudio(this)" /><audio src="'+data[ritem].url+'"></audio>'+data[ritem].title+'</li>';
				}
			}else if(n==4){
				for(ritem in data){
					str+='<li class="showmedia_video" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><video src="'+data[ritem].url+'" controls width="200"></video><br>'+data[ritem].title+'<br>'+data[ritem].content+'</li>';
				}
			}else if(n==5){
				for(ritem in data){
					str+='<li class="showmedia_news" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><dl><img src="'+data[ritem].url+'" width="100%"><dd>'+data[ritem].ntitle+'</dd></dl></li>';
				}
			}
			$("#show"+type+"list").append(str);
			$("#shade").show();
			$("#showmedialist").show();
			$("#show"+type+"list").show();
		}
	},'json');
}
function playaudio(obj){
	if($(obj).next("audio").get(0).paused){
		$(obj).next("audio").get(0).play();
		$(obj).attr("src","<{$ipath}>wx/images/voice_play.gif");
	}else{
		$(obj).next("audio").get(0).pause();
		$(obj).attr("src","<{$ipath}>wx/images/voice_stop.gif");
	}
}
function closehidd(){
	$(".hidddiv").hide();
	$("#shade").hide();
}
function setmediashowid(mid,url,obj){
	$("#mediashowid").val(mid);
	$("#mediashowurl").val(url);
	$("#mediashowsetbutton").attr("class","wxbutton");
	$("#mediashowsetbutton").attr("onclick","setmedia()");
	$(obj).parent().find(".icon_issel").remove();
	$(obj).append('<i class="icon_issel"></i>');
	if($(obj).find("dd").length>0){
		$("#mediashowtomore").val($(obj).find("dd").html());
	}
}
function setmedia(){
	var type = $("#selbytype").val();
	var media_id=$("#mediashowid").val();
	var url=$("#mediashowurl").val();
	if(type==2){
		$("#putcon2 .request_item").html('<img src="'+url+'" style="max-width:300px" /><input type="hidden" name="media_id" value="'+media_id+'" />');
		$("#putcon2 .request_item").show();
		$("#putcon2 .request_add").hide();
		$("#putcon2 .setbutton").show();
		$("#putcon2 .addbutton").hide();
		$("#putcon2").find("h5").append(' <input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材" />');
	}else if(type==3){
		$("#putcon3 .request_item").html('<audio controls src="'+url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id" value="'+media_id+'" />');
		$("#putcon3 .request_item").show();
		$("#putcon3 .request_add").hide();
		$("#putcon3 .setbutton").show();
		$("#putcon3 .addbutton").hide();
		$("#putcon3").find("h5").append(' <input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材" />');
	}else if(type==4){
		$("#putcon4 .request_item").html('<video width="300" controls src="'+url+'">您的浏览器不支持H5视频播放</video><input type="hidden" name="media_id" value="'+media_id+'" />');
		$("#putcon4 .request_item").show();
		$("#putcon4 .request_add").hide();
		$("#putcon4 .setbutton").show();
		$("#putcon4 .addbutton").hide();
		$("#putcon4").find("h5").append(' <input type="button" class="wxsubmit delbutton" onclick="delmedia(this)"   value="删除素材"/>');
	}else if(type==5){
		var title = $("#mediashowtomore").val();
		$("#putcon5 .request_item").html('<dl><img src="'+url+'" width="100%" /><dd>'+title+'</dd></dl><input type="hidden" name="media_id" value="'+media_id+'" />');
		$("#putcon5 .request_item").show();
		$("#putcon5 .request_add").hide();
		$("#putcon5 .setbutton").show();
		$("#putcon5 .addbutton").hide();
		$("#putcon5").find("h5").append(' <input type="button" class="wxsubmit delbutton" onclick="delmedia(this)" value="删除素材" />');
	}
	closeshowmedialist();
}
function closeshowmedialist(){
	$("#shade").hide();
	$("#showmedialist").hide();
	$("#mediashowsetbutton").attr("onclick",'');
	$("#mediashowsetbutton").attr("class","wxbutton_cancel");
	$("#showmedialist").children("ul").html('');
	$("#showmedialist").children("ul").hide();
}
</script>
<iframe width="0" height="0" id="hiddfrm" name="hiddfrm" scrolling="no" frameborder="0" style="display:none"></iframe>
</body>
</html>
